import LevelBaseControl from "../../../LevelCommon/LevelBaseControl";
import EnumData from "../../../../Enum/EnumData";

export default class ArrowLock extends Laya.Script3D{
     /** 正确的值*/
     public  correctDirs:Array<EnumData.ArrowDirEnum> = new Array<EnumData.ArrowDirEnum>();
    /** 当前是否开了*/
    private isOpen: boolean = false;
    /** 输入list*/
    private curInputList: Array<EnumData.ArrowDirEnum> = new Array<EnumData.ArrowDirEnum>();

    public InputDir(dir: EnumData.ArrowDirEnum): void
     {
         if (this.isOpen)
         {
             return;
        }
        this.curInputList.push(dir);
         if (this.IsCorrect())
         {
             this.isOpen = true;
             console.log("正确了！！！！！！！！！");
             let curLevelControl: LevelBaseControl = window.gameFacade.LevelMng.GetCurLevelControl();
             curLevelControl.DoInteractObjLogic(this.owner.name + "_ArrowUnlocked");
         }
         /** 判断长度 如果大于正确长度 就删去超过的部分*/
         else
         {
             let correctLength: number = this.correctDirs.length;
             if (this.curInputList.length > correctLength)
             {
                 /** 超过的个数*/
                 let moreNum: number = this.curInputList.length - correctLength;
                 this.curInputList.splice(0, moreNum);                              
             }
         }
     }
    /** 判断对不对*/
    private IsCorrect(): boolean
     {
         let correctLength = this.correctDirs.length;
         let curInputCount = this.curInputList.length;
         if (curInputCount < correctLength)
         {
             return false;
         }
         let correctIndex = 0;
         for (let i = curInputCount - correctLength; i < curInputCount; i++)
         {
             if (this.curInputList[i] != this.correctDirs[correctIndex])
             {
                 return false;
             }
             correctIndex++;
         }
         return true;       
     }
}